API Documentation
Public Member Functions | List of all members
nkWinUi::Component Class Referenceabstract

Base class for any graphical component. More...

Inheritance diagram for nkWinUi::Component:
nkExport::Exportable nkWinUi::Button nkWinUi::CheckBox nkWinUi::ComboBox nkWinUi::EditBox nkWinUi::FileExplorer nkWinUi::GraphicsWindow nkWinUi::GroupBox nkWinUi::ListBox nkWinUi::LogWin nkWinUi::MultiLineEdit nkWinUi::ProgressBar nkWinUi::ScrollBar nkWinUi::Slider nkWinUi::Static nkWinUi::TabWindow nkWinUi::TreeView nkWinUi::Window

Public Member Functions

 Component ()
 
virtual ~Component ()
 
LayoutgetLayout () const
 
nkMaths::Point getPositionInParent () const
 
nkMaths::Point getPositionInScreen () const
 
int getWidth () const
 
int getHeight () const
 
nkMaths::Rectangle getArea () const
 
virtual nkMaths::Point getBorderExtents () const
 
virtual int getLayoutAllowedWidth () const
 
virtual int getLayoutAllowedHeight () const
 
virtual int getLayoutAllowedOffsetX () const
 
virtual int getLayoutAllowedOffsetY () const
 
bool isInitialized () const
 
ComponentgetParentComponent () const
 
COMPONENT_TYPE getComponentType () const
 
const char * getComponentName () const
 
bool getVisibility () const
 
virtual const char * getLabel () const
 
void * getData () const
 
bool isEnabled () const
 
bool isForegroundWindow () const
 
unsigned int getZDepth () const
 
bool getVisibleOnLoad () const
 
virtual LayoutsetLayout (LAYOUT_TYPE layoutType)
 
virtual void setPositionInParent (nkMaths::Point position)
 
virtual void setPositionInScreen (nkMaths::Point position)
 
virtual void setSize (int width, int height)
 
virtual void setWidth (int width)
 
virtual void setHeight (int height)
 
void setMinSize (unsigned int width, unsigned int height)
 
void setMaxSize (unsigned int width, unsigned int height)
 
void setRatio (float widthOverHeight)
 
virtual void setArea (nkMaths::Rectangle area)
 
virtual void setParentComponent (Component *parent, bool makeItVisible=true)
 
virtual void setLabel (const std::string_view &label)
 
void setComponentName (const std::string_view &name)
 
virtual void setVisibility (bool value)
 
void setData (void *data)
 
void setEnabled (bool value)
 
void setVisibleOnLoad (bool value)
 
void addChild (Component *child, bool makeItVisible=true)
 
void removeChild (Component *child)
 
void removeChild (unsigned int index)
 
ComponentgetChild (unsigned int index)
 
unsigned int getChildIndex (Component *child)
 
void unloadWithChildren ()
 
void loadWithChildren ()
 
void updateZDepth ()
 
void bringToForeground ()
 
void focusWindow ()
 
nkMaths::Point getCoordRelativeFromAbsolute (const nkMaths::Point &absCoords)
 
nkMaths::Point getCoordAbsoluteFromRelative (const nkMaths::Point &relCoords)
 
virtual void load ()=0
 
virtual void unload ()=0
 
virtual void updateWindow ()
 
nkImages::Image paintToImage ()
 
void simulateEvent (const InputDescriptor &inputDescription)
 
void onSized ()
 
ContextMenucreateContextMenu ()
 
ContextMenugetCurrentContextMenu ()
 
void shutContextMenu ()
 
virtual void exportClassToTree (nkExport::Node *rootNode) override
 
virtual void exportIntrospection (nkExport::Node *rootNode)
 
virtual void importClassFromTree (nkExport::Node *rootNode) override
 
- Public Member Functions inherited from nkExport::Exportable
 Exportable ()
 
virtual ~Exportable ()
 

Detailed Description

Base class for any graphical component.

Constructor & Destructor Documentation

◆ Component()

nkWinUi::Component::Component ( )

Constructor.

◆ ~Component()

virtual nkWinUi::Component::~Component ( )
virtual

Destructor.

Member Function Documentation

◆ getLayout()

Layout* nkWinUi::Component::getLayout ( ) const
Returns
The layout currently associated to the component.

◆ getPositionInParent()

nkMaths::Point nkWinUi::Component::getPositionInParent ( ) const
Returns
The component's position, relative to its parent.

◆ getPositionInScreen()

nkMaths::Point nkWinUi::Component::getPositionInScreen ( ) const
Returns
The component's position, absolute, on screen.

◆ getWidth()

int nkWinUi::Component::getWidth ( ) const
Returns
Current component's width.

◆ getHeight()

int nkWinUi::Component::getHeight ( ) const
Returns
Current component's height.

◆ getArea()

nkMaths::Rectangle nkWinUi::Component::getArea ( ) const
Returns
Current component's occupied area.

◆ getBorderExtents()

virtual nkMaths::Point nkWinUi::Component::getBorderExtents ( ) const
virtual
Returns
the size of components borders.

◆ getLayoutAllowedWidth()

virtual int nkWinUi::Component::getLayoutAllowedWidth ( ) const
virtual
Returns
The width the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedHeight()

virtual int nkWinUi::Component::getLayoutAllowedHeight ( ) const
virtual
Returns
The height the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedOffsetX()

virtual int nkWinUi::Component::getLayoutAllowedOffsetX ( ) const
virtual
Returns
The offset for x position the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ getLayoutAllowedOffsetY()

virtual int nkWinUi::Component::getLayoutAllowedOffsetY ( ) const
virtual
Returns
The offset for y position the layout is allowed to take to organize children components.

Reimplemented in nkWinUi::GroupBox.

◆ isInitialized()

bool nkWinUi::Component::isInitialized ( ) const
Returns
Whether component is initialized (successful call to load() has been made).

◆ getParentComponent()

Component* nkWinUi::Component::getParentComponent ( ) const
Returns
The component's parent.

◆ getComponentType()

COMPONENT_TYPE nkWinUi::Component::getComponentType ( ) const
Returns
The type of the component.

◆ getComponentName()

const char* nkWinUi::Component::getComponentName ( ) const
Returns
The name of the component.

◆ getVisibility()

bool nkWinUi::Component::getVisibility ( ) const
Returns
Whether the component is visible (true) or not (false).

◆ getLabel()

virtual const char* nkWinUi::Component::getLabel ( ) const
virtual
Returns
Currently set component's label.

◆ getData()

void* nkWinUi::Component::getData ( ) const
Returns
Currently set user data, attached to the component.

◆ isEnabled()

bool nkWinUi::Component::isEnabled ( ) const
Returns
If the component is enabled (true) or not (false).

◆ isForegroundWindow()

bool nkWinUi::Component::isForegroundWindow ( ) const
Returns
Whether the component is in foreground (true) or not (false).

◆ getZDepth()

unsigned int nkWinUi::Component::getZDepth ( ) const
Returns
The z depth of the component.

◆ getVisibleOnLoad()

bool nkWinUi::Component::getVisibleOnLoad ( ) const
Returns
Whether the component is flagged as needing to be visible (true) or not (false), after a call to load().

◆ setLayout()

virtual Layout* nkWinUi::Component::setLayout ( LAYOUT_TYPE  layoutType)
virtual

Sets the component's layout type by instantiating a new layout, and returns it for populating.

Parameters
layoutTypeThe type of layout the component should instantiate.
Returns
The layout newly assigned.
Remarks
This function will replace any existing layout, and start with a fresh layout. The component is the owner of the layout.

Reimplemented in nkWinUi::TabWindow.

◆ setPositionInParent()

virtual void nkWinUi::Component::setPositionInParent ( nkMaths::Point  position)
virtual

Change the component's position, relative to the parent.

Parameters
positionThe position to assign, in pixels.

◆ setPositionInScreen()

virtual void nkWinUi::Component::setPositionInScreen ( nkMaths::Point  position)
virtual

Change the component's position, relative to screen (absolute).

Parameters
positionThe position to assign, in pixels.

◆ setSize()

virtual void nkWinUi::Component::setSize ( int  width,
int  height 
)
virtual

Change the component's size.

Parameters
widthThe width to assign, in pixels.
heightThe height to assign, in pixels.

◆ setWidth()

virtual void nkWinUi::Component::setWidth ( int  width)
virtual

Change the component's width.

Parameters
widthThe width to assign, in pixels.

◆ setHeight()

virtual void nkWinUi::Component::setHeight ( int  height)
virtual

Change the component's height.

Parameters
heightThe height to assign, in pixels.

◆ setMinSize()

void nkWinUi::Component::setMinSize ( unsigned int  width,
unsigned int  height 
)

Assign a minimum size the component should have.

Parameters
widthThe minimum width possible, in pixels. -1 symbolizes "no limit".
heightThe minimum height possible, in pixels. -1 symbolizes "no limit".

◆ setMaxSize()

void nkWinUi::Component::setMaxSize ( unsigned int  width,
unsigned int  height 
)

Assign a maximum size the component should have.

Parameters
widthThe maximum width possible, in pixels. -1 symbolizes "no limit".
heightThe maximum height possible, in pixels. -1 symbolizes "no limit".

◆ setRatio()

void nkWinUi::Component::setRatio ( float  widthOverHeight)

Assign a ratio the component has to respect.

Parameters
widthOverHeightThe ratio, as width / height.

◆ setArea()

virtual void nkWinUi::Component::setArea ( nkMaths::Rectangle  area)
virtual

Assign an area the component should cover.

Parameters
areaThe area, in pixels, to cover.

◆ setParentComponent()

virtual void nkWinUi::Component::setParentComponent ( Component parent,
bool  makeItVisible = true 
)
virtual

Changes the parent component.

Parameters
parentThe parent component to assign.
makeItVisibleIf the component should be made visible within the parent, if the parent is visible.

Reimplemented in nkWinUi::Popup.

◆ setLabel()

virtual void nkWinUi::Component::setLabel ( const std::string_view &  label)
virtual

Changes the label of the component. This can be the title of a nkWinUi::Window, the txt of a nkWinUi::EditBox...

Parameters
labelThe text to assign.

◆ setComponentName()

void nkWinUi::Component::setComponentName ( const std::string_view &  name)

Sets the component name.

Parameters
nameThe name to assign.
Remarks
In theory, this should not be called by external code. Used by the nkWinUi::ComponentManager upon component's creation.

◆ setVisibility()

virtual void nkWinUi::Component::setVisibility ( bool  value)
virtual

Sets whether this component should be visible.

Parameters
valueIf the component should be visible on screen (true) or not (false).

◆ setData()

void nkWinUi::Component::setData ( void *  data)

Attach user data to the component.

Parameters
dataThe user data to attach to the component.
Remarks
The component will not be responsible for freeing the user data. External code needs to take care of it.

◆ setEnabled()

void nkWinUi::Component::setEnabled ( bool  value)

Sets whether the component is enabled or not.

Parameters
valueIf it is enabled (true) or not (false).
Remarks
A disabled component often appears grayed out, with no interaction possible.

◆ setVisibleOnLoad()

void nkWinUi::Component::setVisibleOnLoad ( bool  value)

Sets whether a component should be visible after its load operation, or not. This can be used to load components but keep them hidden until further notice.

Parameters
valueIf the component should be visible (true) or not (false).

◆ addChild()

void nkWinUi::Component::addChild ( Component child,
bool  makeItVisible = true 
)

Add a child component.

Parameters
childThe component that should become a child.
makeItVisibleIf the child component has to become visible if the parent is also visible.

◆ removeChild() [1/2]

void nkWinUi::Component::removeChild ( Component child)

Removes a child.

Parameters
childThe child component that should not be a child anymore.

◆ removeChild() [2/2]

void nkWinUi::Component::removeChild ( unsigned int  index)

Removes a child.

Parameters
indexThe index of the child component, in the children list, that should be removed.
Remarks
An out of bounds index results in a no-op.

◆ getChild()

Component* nkWinUi::Component::getChild ( unsigned int  index)

Returns a child component.

Parameters
indexThe child component at given index, in the children list.
Returns
The designated child component if index is valid, nullptr else.

◆ getChildIndex()

unsigned int nkWinUi::Component::getChildIndex ( Component child)

Returns the index in the list of one child component.

Parameters
childThe child component chich index is needed.
Returns
The index attached in the list if component is a child, an invalid one (> to children count) else.
Remarks
Index is potentially invalidated if a child is removed in between. However, adding a child won't invalidate it.

◆ unloadWithChildren()

void nkWinUi::Component::unloadWithChildren ( )

Unloads the component along with its children.

◆ loadWithChildren()

void nkWinUi::Component::loadWithChildren ( )

Loads the component along with its children.

◆ updateZDepth()

void nkWinUi::Component::updateZDepth ( )

Updates the depth of the component. Computed from the component's hierarchy.

◆ bringToForeground()

void nkWinUi::Component::bringToForeground ( )

Brings the component to the foreground.

◆ focusWindow()

void nkWinUi::Component::focusWindow ( )

Puts the component into focus.

◆ getCoordRelativeFromAbsolute()

nkMaths::Point nkWinUi::Component::getCoordRelativeFromAbsolute ( const nkMaths::Point absCoords)

Converts given coordinates from absolute in screen to relative to the component.

Parameters
absCoordsThe absolute coordinates to convert.
Returns
The coordinate now relative to the component.

◆ getCoordAbsoluteFromRelative()

nkMaths::Point nkWinUi::Component::getCoordAbsoluteFromRelative ( const nkMaths::Point relCoords)

Converts given coordinates from relative to the component to absolute in screen.

Parameters
relCoordsThe relative coordinates to convert.
Returns
The coordinate now absolute in screen.

◆ load()

virtual void nkWinUi::Component::load ( )
pure virtual

Loads the component. This will trigger the initialization of the component in the windowing system.

◆ unload()

virtual void nkWinUi::Component::unload ( )
pure virtual

Unloads the component. This will make the component release resources from the windowing system.

◆ updateWindow()

virtual void nkWinUi::Component::updateWindow ( )
virtual

Update the window for changes that could have occurred.

◆ paintToImage()

nkImages::Image nkWinUi::Component::paintToImage ( )
Returns
An offscreen rendering of the component.
Remarks
Currently, all components are compatible except for :

◆ simulateEvent()

void nkWinUi::Component::simulateEvent ( const InputDescriptor inputDescription)

Simulates an event within the component, fitting the description given. Using this, it is possible to automatically hover components, or automatically generate keyboard events. Note that simulating an event will not impact the system's input system (cursor or focus).

Parameters
inputDescriptionThe description of the input to simulate.

◆ onSized()

void nkWinUi::Component::onSized ( )

Component's callback for resize events.

◆ createContextMenu()

ContextMenu* nkWinUi::Component::createContextMenu ( )
Returns
A newly created context menu linked to the component.
Remarks
Component is the owner of the context menu. See shutContextMenu if external code needs to delete it.

◆ getCurrentContextMenu()

ContextMenu* nkWinUi::Component::getCurrentContextMenu ( )
Returns
Currently active context menu.

◆ shutContextMenu()

void nkWinUi::Component::shutContextMenu ( )

Shuts and delete current context menu.

◆ exportClassToTree()

virtual void nkWinUi::Component::exportClassToTree ( nkExport::Node rootNode)
overridevirtual

A basic exporting capability.

Parameters
rootNodeThe root of the tree to export into.

Implements nkExport::Exportable.

◆ exportIntrospection()

virtual void nkWinUi::Component::exportIntrospection ( nkExport::Node rootNode)
virtual

A basic exporting capability, for components inheriting. Components inheriting this class should rather reimplement this function to export their internal data.

Parameters
rootNodeThe root of the tree to export into.

Reimplemented in nkWinUi::TreeView, nkWinUi::ListBox, nkWinUi::TabWindow, nkWinUi::ComboBox, nkWinUi::FileExplorer, nkWinUi::GraphicsWindow, nkWinUi::Static, nkWinUi::EditBox, nkWinUi::LogWin, and nkWinUi::Window.

◆ importClassFromTree()

virtual void nkWinUi::Component::importClassFromTree ( nkExport::Node rootNode)
overridevirtual

A basic importing capability.

Parameters
rootNodeThe root of the tree to import from.

Implements nkExport::Exportable.

Reimplemented in nkWinUi::TreeView, nkWinUi::ListBox, nkWinUi::TabWindow, nkWinUi::ComboBox, nkWinUi::FileExplorer, nkWinUi::GraphicsWindow, nkWinUi::Static, nkWinUi::EditBox, nkWinUi::LogWin, and nkWinUi::Window.


The documentation for this class was generated from the following file: